package com.ljs.myspringboot.util;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
@AllArgsConstructor
//用来转换json的格式的类
public class JsonResult implements Serializable {
    public static final int SUCCESS = 1;
    public static final int ERROR = 0;

    private int code;
    private Object data;
    private String msg;
    private int state;

    public JsonResult() {
        state = SUCCESS;
    }

    public JsonResult(String msg, int code) {
        state = ERROR;
        data = null;
        this.code = code;
        this.msg = msg;
    }

    public JsonResult(Object data) {
        state = SUCCESS;
        this.data = data;
    }

    public JsonResult(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "code=" + code +
                ", data=" + data +
                ", msg='" + msg + '\'' +
                ", state=" + state +
                '}';
    }
}
